/**
 * 2009 David BY Chan$lifesting@gmail.com
 *
 * $Id$
 */
package com.lifesting.wfs.gd.impl;

import com.lifesting.wfs.gd.Auto;
import com.lifesting.wfs.gd.End;
import com.lifesting.wfs.gd.Fork;
import com.lifesting.wfs.gd.GdPackage;
import com.lifesting.wfs.gd.Join;
import com.lifesting.wfs.gd.ProcessDefinition;
import com.lifesting.wfs.gd.Start;
import com.lifesting.wfs.gd.TaskRunner;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.BasicFeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Process Definition</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getStart <em>Start</em>}</li>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getGroup <em>Group</em>}</li>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getFork <em>Fork</em>}</li>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getJoin <em>Join</em>}</li>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getAuto <em>Auto</em>}</li>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getTaskRunner <em>Task Runner</em>}</li>
 *   <li>{@link com.lifesting.wfs.gd.impl.ProcessDefinitionImpl#getEnd <em>End</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ProcessDefinitionImpl extends GraphElementImpl implements ProcessDefinition {
	/**
	 * The cached value of the '{@link #getStart() <em>Start</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStart()
	 * @generated
	 * @ordered
	 */
	protected Start start;

	/**
	 * The cached value of the '{@link #getGroup() <em>Group</em>}' attribute list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGroup()
	 * @generated
	 * @ordered
	 */
	protected FeatureMap group;

	/**
	 * The cached value of the '{@link #getEnd() <em>End</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEnd()
	 * @generated
	 * @ordered
	 */
	protected End end;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ProcessDefinitionImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GdPackage.Literals.PROCESS_DEFINITION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Start getStart() {
		return start;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetStart(Start newStart, NotificationChain msgs) {
		Start oldStart = start;
		start = newStart;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS_DEFINITION__START, oldStart, newStart);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStart(Start newStart) {
		if (newStart != start) {
			NotificationChain msgs = null;
			if (start != null)
				msgs = ((InternalEObject)start).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS_DEFINITION__START, null, msgs);
			if (newStart != null)
				msgs = ((InternalEObject)newStart).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS_DEFINITION__START, null, msgs);
			msgs = basicSetStart(newStart, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS_DEFINITION__START, newStart, newStart));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FeatureMap getGroup() {
		if (group == null) {
			group = new BasicFeatureMap(this, GdPackage.PROCESS_DEFINITION__GROUP);
		}
		return group;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Fork> getFork() {
		return getGroup().list(GdPackage.Literals.PROCESS_DEFINITION__FORK);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Join> getJoin() {
		return getGroup().list(GdPackage.Literals.PROCESS_DEFINITION__JOIN);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Auto> getAuto() {
		return getGroup().list(GdPackage.Literals.PROCESS_DEFINITION__AUTO);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<TaskRunner> getTaskRunner() {
		return getGroup().list(GdPackage.Literals.PROCESS_DEFINITION__TASK_RUNNER);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public End getEnd() {
		return end;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetEnd(End newEnd, NotificationChain msgs) {
		End oldEnd = end;
		end = newEnd;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS_DEFINITION__END, oldEnd, newEnd);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEnd(End newEnd) {
		if (newEnd != end) {
			NotificationChain msgs = null;
			if (end != null)
				msgs = ((InternalEObject)end).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS_DEFINITION__END, null, msgs);
			if (newEnd != null)
				msgs = ((InternalEObject)newEnd).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GdPackage.PROCESS_DEFINITION__END, null, msgs);
			msgs = basicSetEnd(newEnd, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GdPackage.PROCESS_DEFINITION__END, newEnd, newEnd));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GdPackage.PROCESS_DEFINITION__START:
				return basicSetStart(null, msgs);
			case GdPackage.PROCESS_DEFINITION__GROUP:
				return ((InternalEList<?>)getGroup()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS_DEFINITION__FORK:
				return ((InternalEList<?>)getFork()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS_DEFINITION__JOIN:
				return ((InternalEList<?>)getJoin()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS_DEFINITION__AUTO:
				return ((InternalEList<?>)getAuto()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS_DEFINITION__TASK_RUNNER:
				return ((InternalEList<?>)getTaskRunner()).basicRemove(otherEnd, msgs);
			case GdPackage.PROCESS_DEFINITION__END:
				return basicSetEnd(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GdPackage.PROCESS_DEFINITION__START:
				return getStart();
			case GdPackage.PROCESS_DEFINITION__GROUP:
				if (coreType) return getGroup();
				return ((FeatureMap.Internal)getGroup()).getWrapper();
			case GdPackage.PROCESS_DEFINITION__FORK:
				return getFork();
			case GdPackage.PROCESS_DEFINITION__JOIN:
				return getJoin();
			case GdPackage.PROCESS_DEFINITION__AUTO:
				return getAuto();
			case GdPackage.PROCESS_DEFINITION__TASK_RUNNER:
				return getTaskRunner();
			case GdPackage.PROCESS_DEFINITION__END:
				return getEnd();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GdPackage.PROCESS_DEFINITION__START:
				setStart((Start)newValue);
				return;
			case GdPackage.PROCESS_DEFINITION__GROUP:
				((FeatureMap.Internal)getGroup()).set(newValue);
				return;
			case GdPackage.PROCESS_DEFINITION__FORK:
				getFork().clear();
				getFork().addAll((Collection<? extends Fork>)newValue);
				return;
			case GdPackage.PROCESS_DEFINITION__JOIN:
				getJoin().clear();
				getJoin().addAll((Collection<? extends Join>)newValue);
				return;
			case GdPackage.PROCESS_DEFINITION__AUTO:
				getAuto().clear();
				getAuto().addAll((Collection<? extends Auto>)newValue);
				return;
			case GdPackage.PROCESS_DEFINITION__TASK_RUNNER:
				getTaskRunner().clear();
				getTaskRunner().addAll((Collection<? extends TaskRunner>)newValue);
				return;
			case GdPackage.PROCESS_DEFINITION__END:
				setEnd((End)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GdPackage.PROCESS_DEFINITION__START:
				setStart((Start)null);
				return;
			case GdPackage.PROCESS_DEFINITION__GROUP:
				getGroup().clear();
				return;
			case GdPackage.PROCESS_DEFINITION__FORK:
				getFork().clear();
				return;
			case GdPackage.PROCESS_DEFINITION__JOIN:
				getJoin().clear();
				return;
			case GdPackage.PROCESS_DEFINITION__AUTO:
				getAuto().clear();
				return;
			case GdPackage.PROCESS_DEFINITION__TASK_RUNNER:
				getTaskRunner().clear();
				return;
			case GdPackage.PROCESS_DEFINITION__END:
				setEnd((End)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GdPackage.PROCESS_DEFINITION__START:
				return start != null;
			case GdPackage.PROCESS_DEFINITION__GROUP:
				return group != null && !group.isEmpty();
			case GdPackage.PROCESS_DEFINITION__FORK:
				return !getFork().isEmpty();
			case GdPackage.PROCESS_DEFINITION__JOIN:
				return !getJoin().isEmpty();
			case GdPackage.PROCESS_DEFINITION__AUTO:
				return !getAuto().isEmpty();
			case GdPackage.PROCESS_DEFINITION__TASK_RUNNER:
				return !getTaskRunner().isEmpty();
			case GdPackage.PROCESS_DEFINITION__END:
				return end != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (group: ");
		result.append(group);
		result.append(')');
		return result.toString();
	}

} //ProcessDefinitionImpl
